#ifndef  LOG_FILE_H
#define  LOG_FILE_H

#include <QtCore>

#include "TranSrv.h"

#define KG_LOG_INFO(MESSAGE)\
do{ \
        QString strInfor;\
        QString currentFileName = QFileInfo(__FILE__).fileName();\
        QString currentFileLine = QString::number(__LINE__);\
        strInfor = currentFileName + "(" + currentFileLine + ") " + MESSAGE;\
        if (0 != g_pLogic) { g_pLogic->WriteLog(strInfor); }\
} while(0)

//统一写日志信息到日志文件(../log/***.log)
class CLogFile
{
public:
    CLogFile(int iFileMaxSize = 5, int iFileNameType = 0);
    ~CLogFile();

public:
    void CreateFile(QString strFileName = "");
    void WriteLog(const QString& strInfo);
    int  GetFileSize();
    void CloseFile();
    void SetIsWriteLog(bool bIsWriteLog);
    void SetFileMaxSize(int iFileMaxSize);
    void SetFileNameType(int iFileNameType);
    QString GetFileName();

private:
    QFile               m_file;
    QString             m_strPath;
    QMutex              m_mutexLog;
    qint32              m_iFileMaxSize; //日志文件最大大小,单位为兆,默认为5兆,日志文件已超过5兆则不写入
    bool                m_bIsWriteLog;  //是否写日志
    //文件名称类型,0为abc.log,1为abc(yyyy).log,2为abc(yyyyMM).log,3为abc(yyyyMMdd).log,默认为0
    int                 m_iFileNameType;
};

#endif

